#pragma once

#include "znx_http_site_conf.h"
#include "comm/znx_rwlock.h"
#include "comm/znx_hash_tab.h"

// Scan directories and load config files.
// TODO: Later, lazy loading will be implemented.

typedef struct {
    znx_hash_tab_t                      *hash_tab;
    znx_rwlock_t                        *rwlocks;
    znx_str_t                           err;
} znx_http_site_mgr_t;


void znx_g_http_site_mgr_create();

void znx_g_http_site_mgr_destroy();

// Scan directories and load config files.
// We will log the error to site_mgr->err.
znx_bool_t znx_g_http_site_mgr_init(const char *site_conf_dir);


znx_http_addr_site_conf_t *znx_http_addr_site_lookup(znx_str_t *host,
    znx_address_t *listen_address, znx_bool_t *not_found, char **err);

static inline void
znx_http_addr_site_conf_free(znx_http_addr_site_conf_t *addr_site)
{
    znx_http_site_conf_free(addr_site->site_conf);
}

